﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}
<script>
    var keyValue = request('keyValue');
    var OrganizeId = request('OrganizeId');
    var DepartmentId = request('DepartmentId');
    var instanceId = "";
    var formId = "";
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //性别
        $("#Gender").ComboBox({
            data: [{ key: 1, value: "男" }, { key: 0, value: "女" }],
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        $("#Gender").ComboBoxSetValue(1);

        //所属楼盘
        $("#PStructId").ComboBoxTree({
            //  url: "../..//ResourceManage/RS_PStructs/GetTreeJson?type=1",
            description: "==请选择==",
            height: "200px",
            allowSearch: true,
        });
        //部门
        $("#DepartmentId").ComboBoxTree({
            //  url: "../../BaseManage/Department/GetOrganizeTreeJson",
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });

        //角色
        $("#RoleId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });
        //岗位
        $("#DutyId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });
        //职位
        $("#PostId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });

        //公司
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择==",
            height: "200px",
            allowSearch: true,
        }).bind("change", function () {
            var value = $(this).attr('data-value');
            //加载楼盘
            $("#PStructId").ComboBoxTree({
                url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=1&OrganizeId=" + value,
                description: "==请选择==",
                height: "200px",
                allowSearch: true
            })
            //加载部门
            $("#DepartmentId").ComboBoxTree({
                url: "../../BaseManage/Department/GetOrganizeTreeJson?OrganizeId=" + value,
                description: "==请选择==",
                allowSearch: true
            });
            //职位
            $("#DutyId").ComboBox({
                url: "../../BaseManage/Duty/GetListJson?organizeId=" + value,
                description: "==请选择==",
                height: "200px",
                id: "RoleId",
                text: "FullName",
                allowSearch: true
            });
        });

        //所属楼盘
        $("#PStructId").ComboBoxTree({
            //  url: "../..//ResourceManage/RS_PStructs/GetTreeJson?type=1",
            description: "==请选择==",
            height: "200px",
            allowSearch: true,
        });
        //部门
        $("#DepartmentId").ComboBoxTree({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });

        //加载角色
        $("#RoleId").ComboBox({
            //url: "../../BaseManage/Role/GetListJson?organizeId=" + value,
            url: "../../BaseManage/Role/GetListJson",
            id: "RoleId",
            text: "FullName",
            description: "==请选择==",
            allowSearch: true
        });
        //加载岗位
        $("#PostId").ComboBox({
            //url: "../../BaseManage/Post/GetListJson?organizeId=" + value,
            url: "../../BaseManage/Post/GetListJson",
            id: "RoleId",
            text: "FullName",
            description: "==请选择==",
            allowSearch: true
        });

        if (!!OrganizeId) {
            $("#OrganizeId").ComboBoxTreeSetValue(OrganizeId).trigger('change');
            $("#DepartmentId").ComboBoxTreeSetValue(DepartmentId);
        }
        //加载自定义表单
        //var moduleId = top.$.cookie('currentmoduleId');
        //$.SetForm({
        //    url: "../../AuthorizeManage/ModuleForm/GetEntityJsonByModuleId",
        //    param: { "keyValue": moduleId, "objectId": keyValue },
        //    async: true,
        //    success: function (data) {
        //        $('#frmpreview').frmPreview({
        //            tablecotent: data.form.FormJson,
        //            width: 700
        //        });
        //        formId = data.form.FormId;
        //        if (data.instance != null) {
        //            $('#frmpreview').frmSetData(JSON.parse(data.instance.FormInstanceJson));
        //            instanceId = data.instance.FormInstanceId;
        //        }
        //    }
        //});
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../BaseManage/Worker/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    $("#OrganizeId").trigger("change");
                    $("#DepartmentId").ComboBoxSetValue(data.DepartmentId).trigger("change");

                    $("#PStructId").ComboBoxSetValue(data.PstructId);
                    $("#DutyId").ComboBoxSetValue(data.DutyId)
                    $("#RoleId").ComboBoxSetValue(data.RoleId)
                    $("#PostId").ComboBoxSetValue(data.PostId)
                    $("#Birthday").val(formatDate(data.Birthday, "yyyy-MM-dd"));

                }
            });
        }


    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["DutyName"] = $("#DutyId").attr('data-text');
        postData["PostName"] = $("#PostId").attr('data-text');
        //postData["Manager"] = $("#ManagerId").attr('data-text');
        var _instanceData = $("#frmpreview").frmGetData();
        var moduleFormInstanceEntity = { "FormId": formId, "FormInstanceJson": JSON.stringify(_instanceData) };

        $.SaveForm({
            url: "../../BaseManage/Worker/SaveForm",
            param: { "keyValue": keyValue, "strWorkerEntity": JSON.stringify(postData), "FormInstanceId": instanceId, "strModuleFormInstanceEntity": JSON.stringify(moduleFormInstanceEntity) },
            loading: "正在保存数据...",
            success: function (data) {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
<div style="margin-left: 10px; margin-right: 10px;">
    @*<ul class="nav nav-tabs">
            <li class="active"><a href="#BaseInfo" data-toggle="tab">基本信息</a></li>
            <li><a href="#ExpandInfo" data-toggle="tab">扩展属性</a></li>
        </ul>*@
    <div class="tab-content" style="padding-top: 15px;">
        <div id="BaseInfo" class="tab-pane active" style=" padding-right: 30px;">
            <table class="form">
                <tr>
                    <td class="formTitle">工号<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Code" type="text" onblur="$.ExistField(this.id,'../../BaseManage/Worker/ExistCode')" class="form-control" placeholder="请输入工号" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">姓名<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Name" type="text" class="form-control" placeholder="请输入姓名" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">隶属机构<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="OrganizeId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                    <td class="formTitle">部门<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="DepartmentId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">职位</td>
                    <td class="formValue">
                        <div id="DutyId" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
                    </td>
                    <td class="formTitle">岗位</td>
                    <td class="formValue">
                        <div id="PostId" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">角色</td>
                    <td class="formValue">
                        <div id="RoleId" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
                    </td>
                    <td class="formTitle">所属楼盘</td>
                    <td class="formValue">
                        <div id="PStructId" type="selectTree" class="ui-select" ></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">性别</td>
                    <td class="formValue">
                        <div id="Gender" type="selectTree" class="ui-select" isvalid="yes" checkexpession="IsScript">
                        </div>
                    </td>
                    <td class="formTitle">身份证号</td>
                    <td class="formValue">
                        <input id="IDCard" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">入职日期</th>
                    <td class="formValue">
                        <input id="EntryDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({})" />
                    </td>
                    <th class="formTitle">离职职日期</th>
                    <td class="formValue">
                        <input id="LeaveDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({})" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" style="height: 37px;">在职状态</th>
                    <td class="formValue">
                        <div class="checkbox">
                            <label>
                                <input id="State" type="checkbox" checked="checked" />
                                是否在职
                            </label>
                        </div>
                    </td>
                    <th class="formTitle">合同编号</th>
                    <td class="formValue">
                        <input id="ContractNO" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">手机</td>
                    <td class="formValue">
                        <input id="PhoneNum" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                    <td class="formTitle">电话</td>
                    <td class="formValue">
                        <input id="TelPhoneNum" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                    @*<td class="formTitle">生日</td>
                        <td class="formValue">
                            <input id="Birthday" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" />
                        </td>*@
                </tr>
                <tr>
                    <td class="formTitle">紧急联系人</td>
                    <td class="formValue">
                        <input id="LinkMan" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                    <td class="formTitle">紧急联系人电话</td>
                    <td class="formValue">
                        <input id="LinkPhone" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">邮箱</td>
                    <td class="formValue">
                        <input id="Email" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>

                    <td class="formTitle">住址</td>
                    <td class="formValue">
                        <input id="Address" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                </tr>

                <tr>
                    <th class="formTitle">最高学历</th>
                    <td class="formValue">
                        <input id="Education" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                    <th class="formTitle">毕业院校</th>
                    <td class="formValue">
                        <input id="GraduateSchool" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 4px;">
                        备注
                    </th>
                    <td class="formValue" colspan="3">
                        <textarea id="Description" class="form-control" style="height: 50px;" isvalid="yes" checkexpession="IsScript"></textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div id="ExpandInfo" class="tab-pane ">
            <div class="app_layout app_preview" style="border-top: 1px solid #ccc;" id="frmpreview"></div>
        </div>
    </div>
</div>
